#pragma once
#include "IBlockTemplate.h"
#include "IContentLoader.h"
#include <boost/shared_ptr.hpp>
#include <string>
#include <map>
using namespace std;
#define BL_OK 0
#define BL_DUPLICATE_BLOCK -1
#define BL_INVALID_BLOCK -2
#define BL_LOADER_ERROR -3

const uint BlockID_ReservedStart = 1;

typedef boost::shared_ptr<IBlockTemplate> BlockTemplatePtr;
class BlockLibrary
{
public:
	BlockLibrary(void);
	~BlockLibrary(void);
	void PreCalculateBlockTextureMappings();
	void UnloadAllBlockTemplates();
	int RegisterBlockTemplate(BlockTemplatePtr pBlock, IContentLoader *caller);
	int GetFreeBlockID() const;

	//Only usable on build libraries
	const MultiTextureIndex &GetBlockTextureInfo(uint blockID) const;
	//Only usable on build libraries
	uint GetBlockRenderType(uint blockID) const;

	uint GetMaxEntryID() const;
	void BuildBlockLibrary();

private:
	int m_nBuildLibrarySize;
	BlockTemplatePtr *m_pBlockTemplates;
	IContentLoader **m_pRegisteredBy;
	map<uint, BlockTemplatePtr> m_blockTemplates;
	map<uint, IContentLoader*> m_registeredBy;
};

